let resize;

/**
 * @description: 解除rem
 */
export function unUseRem() {
  if (resize) {
    document.documentElement.style.fontSize = '';
    window.removeEventListener('orientationchange' in window ? 'orientationchange' : 'resize', resize);
    document.removeEventListener('DOMContentLoaded', resize);
  }
}


/**
 * @description: 使用rem
 * @param {Number} styleWidth 设计稿px，默认375
 * @param {Number} remUnit 比例默认100
 * @return {void}
 */
export default function useRem(styleWidth = 375, remUnit = 100) {
  if (!resize && document && document.addEventListener) {
    const html = document.documentElement;
    resize = function () {
      html.style.fontSize = remUnit * (html.clientWidth / styleWidth) + 'px';
    };
    window.addEventListener('orientationchange' in window ? 'orientationchange' : 'resize', resize);
    document.addEventListener('DOMContentLoaded', resize);
    resize();
  }
}